package com.mowh.gof23.structural.patterns.proxy;



/**
 * @author mowh1gd
 * @create 2023/10/27 10:29
 */
public class Printer implements Printable {
    private String name;

    public Printer() {
        heavyJob("正在生成Printer的实例");
    }

    public Printer(String name) {
        this.name = name;
        heavyJob("Printer的实例(" + name + ")生成中");
    }

    @Override
    public void setPrinterName(String name) {
        this.name = name;
    }

    @Override
    public String getPrintName() {
        return name;
    }

    @Override
    public void print(String aString) {
        System.out.println("===" + name + "===");
        System.out.println(aString);
    }

    private void heavyJob(String message) {
        System.out.print(message);
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.print(".");
        }
        System.out.println("结束。");
    }
}
